package com.allwees.bs.module.scm.transform;

import com.allwees.bs.core.modelbase.transform.ObjectTransformFactory;
import com.allwees.bs.module.scm.entity.ScmAllocateOrderSku;
import com.allwees.bs.module.scm.entity.ScmPickOrderSku;
import com.allwees.core.common.constant.EStatus;

import java.math.BigDecimal;

public class ScmAllocateOrderSkuToScmPickOrderSkuTransformFactory extends ObjectTransformFactory<ScmAllocateOrderSku, ScmPickOrderSku> {

    @Override
    public boolean match(Class<?> f, Class<?> t) {
        return f.getName().equals(ScmAllocateOrderSku.class.getName()) && t.getName().equals(ScmPickOrderSku.class.getName());
    }

    @Override
    protected ScmPickOrderSku create() {
        return new ScmPickOrderSku();
    }

    @Override
    protected ScmPickOrderSku transform(ScmAllocateOrderSku from, ScmPickOrderSku target) {
        target = super.transform(from, target);

        target.setAllocateOrderSkuUuid(from.getUuid());
        return target;
    }

    @Override
    protected ScmPickOrderSku perfect(ScmPickOrderSku pickOrderSku) {
        pickOrderSku.setEStatus(EStatus.NORMAL);
        pickOrderSku.setShippingQuantity(pickOrderSku.getQuantity());
        pickOrderSku.setSupplyPrice(pickOrderSku.getSupplyPrice() != null ? pickOrderSku.getSupplyPrice() : BigDecimal.ZERO);
        return pickOrderSku;
    }
}
